package com.gddb.xwj.common.api;

import com.gddb.xwj.constants.BaseApiConstants;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author xuwj
 * @Description: 通用baseapi 父类,架构思路二：其实也可以直接封装同通用的JSON返回类
 * @CreateTime 2020/1/8 6:55
 * @Version 1.0
 */
public class BaseApiService {
    /**
     * 功能描述：自定义返回_重载
     * @param code
     * @param msg
     * @param data
     * @return
     */
    public Map<String, Object> setResult(Integer code, String msg, Object data) {
        return setResult(code, msg,true, data);
    }

    /**
     * 功能描述：自定义返回
     * @param code
     * @param msg
     * @param flag
     * @param data
     * @return
     */
    public Map<String, Object> setResult(Integer code, String msg,Boolean flag, Object data) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put(BaseApiConstants.HTTP_RES_CODE_NAME, code);
        result.put(BaseApiConstants.HTTP_RES_MSG_NAME, msg);
        result.put(BaseApiConstants.HTTP_RES_FLAG_NAME, flag);
        if (data != null) {
            result.put(BaseApiConstants.HTTP_RES_DATA_NAME, data);
        }
        return result;
    }

    /**
     *
     * @methodDesc: 功能描述:(返回错误)
     * @param: @param
     *             msg
     * @param: @return
     */
    public Map<String, Object> setResultError(String msg) {
        return setResult(BaseApiConstants.HTTP_RES_CODE_500, msg,true, null);
    }

    /**
     *
     * @methodDesc: 功能描述:(返回成功)
     * @param: @param
     *             msg
     * @param: @return
     */
    public Map<String, Object> setResultSuccessData(Object data) {
        return setResult(BaseApiConstants.HTTP_RES_CODE_200, BaseApiConstants.HTTP_RES_SUCCESS_NAME,true, data);
    }

    /**
     *
     * @methodDesc: 功能描述:(返回成功)
     * @param: @param
     *             msg
     * @param: @return
     */
    public Map<String, Object> setResultSuccess() {
        return setResult(BaseApiConstants.HTTP_RES_CODE_200, BaseApiConstants.HTTP_RES_SUCCESS_NAME,true, null);
    }

    /**
     *
     * @methodDesc: 功能描述:(返回成功)
     * @param: @param
     *             msg
     * @param: @return
     */
    public Map<String, Object> setResultParameterError(String msg) {
        return setResult(BaseApiConstants.HTTP_RES_CODE_200, msg,true, null);
    }
    /**
     *
     * @methodDesc: 功能描述:(返回成功)
     * @param: @param
     *             msg
     * @param: @return
     */
    public Map<String, Object> setResultSuccess(String msg) {
        return setResult(BaseApiConstants.HTTP_RES_CODE_200, msg,true, null);
    }

}
